package xml.xstream;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.StaxDriver;

/**
 * <pre>
 *   Title: XStream0.java
 *   Description: 
 *   Copyright: yundaex.com Copyright (c) 2013
 *   Company: 上海韵达货运有限公司
 * </pre>
 * 
 * @author liuzhaoqing
 * @version 1.0
 * @date 2014年10月23日
 */
class Person {
	private String name;
	int age;
	public StringBuffer sex;
	public void set(String name) {
	   this.name = name;
	}
	public String toString() {
	   return "{name="+name+";age="+age+";sex="+sex+"}";
	}
}
public class XStream0 {
	public static void main(String[] args) {
		Person p = new Person();
		p.sex = new StringBuffer("未知");
		p.set("如花");
		p.age = 70;
		System.out.println("转换之前的Person对象p="+p);
		 
		XStream xstream = new XStream(new StaxDriver());
		String xml = xstream.toXML(p);
		System.out.println("转换生成XML字符串=="+xml);
		Person p2 = (Person) xstream.fromXML(xml);
		System.out.println("转换之后的Person对象p2="+p2);
	}
}
